home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Graphics Programming (2nd Edition) / Visual Basic Graphics Programming 2nd Edition.iso / OldSrc / CH14 / SRC / PARALLEL.FRM (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1996-05-02  |  9.0 KB  |  305 lines

  1. VERSION 4.00
  2. Begin VB.Form ParallelForm 
  3.    Appearance      =   0  'Flat
  4.    BackColor       =   &H00C0C0C0&
  5.    Caption         =   "Parallel"
  6.    ClientHeight    =   5310
  7.    ClientLeft      =   1410
  8.    ClientTop       =   855
  9.    ClientWidth     =   6870
  10.    BeginProperty Font 
  11.       name            =   "MS Sans Serif"
  12.       charset         =   1
  13.       weight          =   700
  14.       size            =   8.25
  15.       underline       =   0   'False
  16.       italic          =   0   'False
  17.       strikethrough   =   0   'False
  18.    EndProperty
  19.    ForeColor       =   &H80000008&
  20.    Height          =   6000
  21.    KeyPreview      =   -1  'True
  22.    Left            =   1350
  23.    LinkTopic       =   "Form1"
  24.    ScaleHeight     =   5310
  25.    ScaleWidth      =   6870
  26.    Top             =   225
  27.    Width           =   6990
  28.    Begin VB.Frame Frame1 
  29.       Caption         =   "Rotations"
  30.       Height          =   2415
  31.       Left            =   5400
  32.       TabIndex        =   1
  33.       Top             =   0
  34.       Width           =   1455
  35.       Begin VB.TextBox XYText 
  36.          Height          =   285
  37.          Left            =   600
  38.          MaxLength       =   6
  39.          TabIndex        =   10
  40.          Text            =   "0.1"
  41.          Top             =   1320
  42.          Width           =   735
  43.       End
  44.       Begin VB.TextBox XZText 
  45.          Height          =   285
  46.          Left            =   600
  47.          MaxLength       =   6
  48.          TabIndex        =   9
  49.          Text            =   "0.2"
  50.          Top             =   1680
  51.          Width           =   735
  52.       End
  53.       Begin VB.TextBox YZText 
  54.          Height          =   285
  55.          Left            =   600
  56.          MaxLength       =   6
  57.          TabIndex        =   8
  58.          Text            =   "0.3"
  59.          Top             =   2040
  60.          Width           =   735
  61.       End
  62.       Begin VB.TextBox XWText 
  63.          Height          =   285
  64.          Left            =   600
  65.          MaxLength       =   6
  66.          TabIndex        =   4
  67.          Text            =   "0.5"
  68.          Top             =   240
  69.          Width           =   735
  70.       End
  71.       Begin VB.TextBox YWText 
  72.          Height          =   285
  73.          Left            =   600
  74.          MaxLength       =   6
  75.          TabIndex        =   3
  76.          Text            =   "0.4"
  77.          Top             =   600
  78.          Width           =   735
  79.       End
  80.       Begin VB.TextBox ZWText 
  81.          Height          =   285
  82.          Left            =   600
  83.          MaxLength       =   6
  84.          TabIndex        =   2
  85.          Text            =   "0.0"
  86.          Top             =   960
  87.          Width           =   735
  88.       End
  89.       Begin VB.Label Label1 
  90.          Caption         =   "XY"
  91.          Height          =   255
  92.          Index           =   5
  93.          Left            =   240
  94.          TabIndex        =   13
  95.          Top             =   1320
  96.          Width           =   375
  97.       End
  98.       Begin VB.Label Label1 
  99.          Caption         =   "XZ"
  100.          Height          =   255
  101.          Index           =   4
  102.          Left            =   240
  103.          TabIndex        =   12
  104.          Top             =   1680
  105.          Width           =   375
  106.       End
  107.       Begin VB.Label Label1 
  108.          Caption         =   "YZ"
  109.          Height          =   255
  110.          Index           =   3
  111.          Left            =   240
  112.          TabIndex        =   11
  113.          Top             =   2040
  114.          Width           =   375
  115.       End
  116.       Begin VB.Label Label1 
  117.          Caption         =   "XW"
  118.          Height          =   255
  119.          Index           =   0
  120.          Left            =   240
  121.          TabIndex        =   7
  122.          Top             =   240
  123.          Width           =   375
  124.       End
  125.       Begin VB.Label Label1 
  126.          Caption         =   "YW"
  127.          Height          =   255
  128.          Index           =   1
  129.          Left            =   240
  130.          TabIndex        =   6
  131.          Top             =   600
  132.          Width           =   375
  133.       End
  134.       Begin VB.Label Label1 
  135.          Caption         =   "ZW"
  136.          Height          =   255
  137.          Index           =   2
  138.          Left            =   240
  139.          TabIndex        =   5
  140.          Top             =   960
  141.          Width           =   375
  142.       End
  143.    End
  144.    Begin VB.PictureBox Pict 
  145.       AutoRedraw      =   -1  'True
  146.       Height          =   5295
  147.       Left            =   0
  148.       ScaleHeight     =   349
  149.       ScaleMode       =   3  'Pixel
  150.       ScaleWidth      =   349
  151.       TabIndex        =   0
  152.       Top             =   0
  153.       Width           =   5295
  154.    End
  155.    Begin VB.Menu mnuFile 
  156.       Caption         =   "&File"
  157.       Begin VB.Menu mnuFileExit 
  158.          Caption         =   "E&xit"
  159.       End
  160.    End
  161. Attribute VB_Name = "ParallelForm"
  162. Attribute VB_Creatable = False
  163. Attribute VB_Exposed = False
  164. Option Explicit
  165. ' Location of focus point.
  166. Const FocusX = 0#
  167. Const FocusY = 0#
  168. Const FocusZ = 0#
  169. Dim ThePicture As ObjPicture
  170. ' *******************************************************
  171. ' Draw the surface.
  172. ' *******************************************************
  173. Private Sub DrawData(pic As Object)
  174. Dim xw_rot As Single
  175. Dim yw_rot As Single
  176. Dim zw_rot As Single
  177. Dim xy_rot As Single
  178. Dim xz_rot As Single
  179. Dim yz_rot As Single
  180. Dim XW(1 To 5, 1 To 5) As Single
  181. Dim YW(1 To 5, 1 To 5) As Single
  182. Dim ZW(1 To 5, 1 To 5) As Single
  183. Dim XY(1 To 5, 1 To 5) As Single
  184. Dim XZ(1 To 5, 1 To 5) As Single
  185. Dim YZ(1 To 5, 1 To 5) As Single
  186. Dim S(1 To 5, 1 To 5) As Single
  187. Dim T(1 To 5, 1 To 5) As Single
  188. Dim M12(1 To 5, 1 To 5) As Single
  189. Dim M34(1 To 5, 1 To 5) As Single
  190. Dim M1_4(1 To 5, 1 To 5) As Single
  191. Dim M56(1 To 5, 1 To 5) As Single
  192. Dim M78(1 To 5, 1 To 5) As Single
  193. Dim M5_8(1 To 5, 1 To 5) As Single
  194. Dim M1_8(1 To 5, 1 To 5) As Single
  195.     If Not IsNumeric(XWText.Text) Then Exit Sub
  196.     If Not IsNumeric(YWText.Text) Then Exit Sub
  197.     If Not IsNumeric(ZWText.Text) Then Exit Sub
  198.     If Not IsNumeric(XYText.Text) Then Exit Sub
  199.     If Not IsNumeric(XZText.Text) Then Exit Sub
  200.     If Not IsNumeric(YZText.Text) Then Exit Sub
  201.     xw_rot = CSng(XWText.Text)
  202.     yw_rot = CSng(YWText.Text)
  203.     zw_rot = CSng(ZWText.Text)
  204.     xy_rot = CSng(XYText.Text)
  205.     xz_rot = CSng(XZText.Text)
  206.     yz_rot = CSng(YZText.Text)
  207.     MousePointer = vbHourglass
  208.     Refresh
  209.     ' Prevent overflow errors when drawing lines
  210.     ' too far out of bounds.
  211.     On Error Resume Next
  212.     ' Calculate the rotation matrices.
  213.     m4XWRotate XW, xw_rot
  214.     m4YWRotate YW, yw_rot
  215.     m4ZWRotate ZW, zw_rot
  216.     m4XYRotate XY, xy_rot
  217.     m4XZRotate XZ, xz_rot
  218.     m4YZRotate YZ, yz_rot
  219.     ' Scale and translate so it looks OK in pixels.
  220.     m4Scale S, 75, -75, 1, 1
  221.     m4Translate T, Pict.ScaleWidth / 2, Pict.ScaleHeight / 2, 0, 0
  222.     m4MatMultiply M12, XW, YW
  223.     m4MatMultiply M34, ZW, XY
  224.     m4MatMultiply M56, XZ, YZ
  225.     m4MatMultiply M78, S, T
  226.     m4MatMultiply M1_4, M12, M34
  227.     m4MatMultiply M5_8, M56, M78
  228.     m4MatMultiply M1_8, M1_4, M5_8
  229.     ' Transform the points.
  230.     ThePicture.Apply M1_8
  231.     ' Display the data.
  232.     pic.Cls
  233.     ThePicture.Draw pic
  234.     pic.Refresh
  235.     MousePointer = vbDefault
  236. End Sub
  237. Private Sub Form_Load()
  238.     ' Create the data.
  239.     CreateData
  240.     ' Project and draw the data.
  241.     Me.Show
  242.     DrawData Pict
  243. End Sub
  244. ' ************************************************
  245. ' Create the surface.
  246. ' ************************************************
  247. Sub CreateData()
  248. Dim pline As ObjPolyline4D
  249. Dim x As Integer
  250. Dim y As Integer
  251. Dim z As Integer
  252. Dim w As Integer
  253.     MousePointer = vbHourglass
  254.     Refresh
  255.     Set ThePicture = New ObjPicture
  256.     Set pline = New ObjPolyline4D
  257.     ThePicture.objects.Add pline
  258.     For x = -1 To 1 Step 2
  259.         For y = -1 To 1 Step 2
  260.             For z = -1 To 1 Step 2
  261.                 For w = -1 To 1 Step 2
  262.                     If x = -1 Then _
  263.                         pline.AddSegment _
  264.                             x, y, z, w, _
  265.                             1, y, z, w
  266.                     If y = -1 Then _
  267.                         pline.AddSegment _
  268.                             x, y, z, w, _
  269.                             x, 1, z, w
  270.                     If z = -1 Then _
  271.                         pline.AddSegment _
  272.                             x, y, z, w, _
  273.                             x, y, 1, w
  274.                     If w = -1 Then _
  275.                         pline.AddSegment _
  276.                             x, y, z, w, _
  277.                             x, y, z, 1
  278.                 Next w
  279.             Next z
  280.         Next y
  281.     Next x
  282.     MousePointer = vbDefault
  283. End Sub
  284. Private Sub mnuFileExit_Click()
  285.     Unload Me
  286. End Sub
  287. Private Sub XYText_Change()
  288.     DrawData Pict
  289. End Sub
  290. Private Sub XZText_Change()
  291.     DrawData Pict
  292. End Sub
  293. Private Sub YWText_Change()
  294.     DrawData Pict
  295. End Sub
  296. Private Sub YZText_Change()
  297.     DrawData Pict
  298. End Sub
  299. Private Sub ZWText_Change()
  300.     DrawData Pict
  301. End Sub
  302. Private Sub XWText_Change()
  303.     DrawData Pict
  304. End Sub
  305.